//
//  YCShakeToEditViewController.m
//  DemoShakeItOff
//
//  Created by 唐可雄 on 16/6/17.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "YCShakeToEditViewController.h"

@interface YCShakeToEditViewController ()

@end

@implementation YCShakeToEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self becomeFirstResponder];
    [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    
    [self resignFirstResponder];
    [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:NO];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

#pragma mark - IBAction

- (IBAction)clearBtnDidClick:(id)sender {
    self.textView.text = nil;
}

#pragma mark - Motion

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (motion == UIEventSubtypeMotionShake) {
         [self.textView setText:[self.textView.text stringByAppendingString:@"开始摇动\n"]];
    }
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (motion == UIEventSubtypeMotionShake) {
        [self.textView setText:[self.textView.text stringByAppendingString:@"结束摇动\n"]];
    }
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (motion == UIEventSubtypeMotionShake) {
        [self.textView setText:[self.textView.text stringByAppendingString:@"取消摇动\n"]];
    }
}

@end
